package com.cloudcc.mobile.presenter;

import com.cloudcc.cloudframe.bus.EventEngine;
import com.cloudcc.cloudframe.net.ErrorInfo;
import com.cloudcc.cloudframe.net.RequestListener;
import com.cloudcc.mobile.dao.MarketActivityEngine;
import com.cloudcc.mobile.dao.impl.MarketActivityEngineImpl;
import com.cloudcc.mobile.event.MarketActivityEventList.MarketCheckByPhoneEvent;
import com.cloudcc.mobile.event.MarketActivityEventList.MarketCheckPhoneNumberEvent;
import com.cloudcc.mobile.event.MarketActivityEventList.MarketCheckResultEvent;
import com.cloudcc.mobile.event.MarketActivityEventList.MarketEventInfoEvent;
import com.cloudcc.mobile.event.MarketActivityEventList.MarketEventListEvent;
import com.cloudcc.mobile.util.VerificateUtils;
import com.litesuits.android.log.Log;

/**
 * 联系人 潜在客户 客户 的具体操作
 * 
 * @Description: TODO()
 * @author wangzhiqiang
 * @date 2016-3-10 下午12:00:10
 * 
 */
public class MarketActivityPresenter extends BasePresenter {

	private MarketActivityEngine mEngine;

	public MarketActivityPresenter() {
		super();
		mEngine = new MarketActivityEngineImpl();
	}

	/**
	 * 查询 市场活动
	 * 
	 * @param page
	 * @param searchKey
	 */
	public void queryMarketActivityList(int page, String searchKey) {
		MarketEventListEvent event = new MarketEventListEvent();
		mEngine.getMarketList(page, searchKey, event);
	}

	/**
	 * 查询 市场活动 详情
	 * 
	 * @param page
	 * @param searchKey
	 */
	public void queryMarketActivityInfo(String id) {
		MarketEventInfoEvent event = new MarketEventInfoEvent();
		mEngine.getMarketList(id, event);
	}

	public void valPhoneNumber(String phoneNubmer, String campaign) {

		MarketCheckPhoneNumberEvent event = new MarketCheckPhoneNumberEvent();
		if (!VerificateUtils.isMobile(phoneNubmer)) {
			event.setOk(false);
			event.setMessage("手机号码不正确!");
			Log.d("phoneerror", "手机号码不正确");
			EventEngine.post(event);
			Log.d("phoneerror", "已经发送");
			return;
		}
		Log.d("phoneerror2", "手机号码出发");
		mEngine.valPhoneNumber(phoneNubmer, campaign, event);

	}

	/**
	 * 市场活动签到
	 * 
	 * @param memberId
	 * @param telephone
	 * @param campaign
	 *            2016-4-5
	 */
	public void checkByQrcode(String memberId, String telephone, String campaign) {
		final MarketCheckResultEvent event = new MarketCheckResultEvent();
		mEngine.checkByQrCode(memberId, telephone, campaign,
				new RequestListener() {

					@Override
					public void onSuccess(Object arg0) {
						Log.d("issuccess", "成功");
						event.setOk(true);
						EventEngine.post(event);
					}

					@Override
					public void onFailure(ErrorInfo error) {
						Log.d("issuccess", "失败");
						event.setOk(false);
						event.setMessage(error.getErrorMessage());
						EventEngine.post(event);
					}
				});

	}

	/**
	 * 通过手机号码签到
	 * 
	 * @param memberId
	 * @param telephone
	 * @param campaign
	 *            2016-4-14
	 */
	public void checkByPhone(String telephone, String campaign) {
		final MarketCheckByPhoneEvent event = new MarketCheckByPhoneEvent();
		mEngine.checkByPhone(telephone, campaign, new RequestListener() {

			@Override
			public void onSuccess(Object arg0) {
				event.setOk(true);
				EventEngine.post(event);
			}

			@Override
			public void onFailure(ErrorInfo error) {
				event.setOk(false);
				event.setMessage(error.getErrorMessage());
				EventEngine.post(event);
			}
		});

	}

}
